//
//  WOTranscript.java
//  WOGroovy
//  Written by Suzuki Tetsuya

package groovy.lang.webobjects.components;

import com.webobjects.foundation.*;
import java.io.*;

public class WOTranscript extends ByteArrayOutputStream implements Serializable {
	public static WOTranscript defaultTranscript;
	
	public static WOTranscript defaultTranscript() {
		if (defaultTranscript == null)
			defaultTranscript = new WOTranscript();
		return defaultTranscript;
	}
	
	public static void setDefaultTranscript(WOTranscript transcript) {
		defaultTranscript = transcript;
	}
	
	public void show(Object object) {
		if (object != null) {
			try {
				write(object.toString().getBytes());
			} catch (IOException e) {
				NSLog.err.appendln("Can't write to transcript: " + e.getMessage());
			}
		}
	}
	
	public NSArray<String> lines() {
		NSMutableArray<String> lines = new NSMutableArray<String>();
		String[] outputs = toString().split("\n");
		for (String line : outputs) {
			lines.addObject(line);
		}
		return lines;
	}
}
